/*
=======================================================================

  BOTS Scientist General Research Menu

=======================================================================
*/
#include "ui_local.h"
#include "ui_BOTS.h"

#define BOTS_SCIENTIST_WEAPONDAMAGE		1
#define BOTS_SCIENTIST_WEAPONFIRERATE	2
#define BOTS_SCIENTIST_REDUCEDAMMO		3
#define BOTS_SCIENTIST_ADVANCEDARMOR	4
#define BOTS_SCIENTIST_HEALTH			5
#define BOTS_SCIENTIST_SPEED			6
#define BOTS_SCIENTIST_JUMP				7
#define BOTS_SCIENTIST_STRENGTH			8
#define BOTS_SCIENTIST_STEALTH			9

typedef struct 
{
  menuframework_s menu;  

  menutext_s	title;
  menutext_s	weapondamage;
  menutext_s	weaponfirerate;
  menutext_s	reducedammo;
  menutext_s	advancedarmor;
  menutext_s	health;
  menutext_s	speed;
  menutext_s	jump;
  menutext_s	strength;
  menutext_s	stealth;
  menutext_s	cancel;
} scientistGenResearchMenu_t;

static scientistGenResearchMenu_t		s_scientistGenResearchMenu;

/*
=================
BOTS_ScientistGenResearchMenu_Event
callback routine
=================
*/
void BOTS_ScientistGenResearchMenu_Event( void *ptr, int notification ) 
{
	char tech[100];
	tech[0] = '\0';

	if( notification != QM_ACTIVATED )
		return;

	// any event will kill the menu
	UI_PopMenu();

	switch( ((menucommon_s*)ptr)->id ) 
	{
	case BOTS_CANCEL:
		break;
	case BOTS_SCIENTIST_WEAPONDAMAGE:
		strcpy(tech, "weapondamage");
		break;
	case BOTS_SCIENTIST_WEAPONFIRERATE:
		strcpy(tech, "firerate");
		break;
	case BOTS_SCIENTIST_REDUCEDAMMO:
		strcpy(tech, "reducedammo");
		break;
	case BOTS_SCIENTIST_ADVANCEDARMOR:
		strcpy(tech, "advancedarmor");
		break;
	case BOTS_SCIENTIST_HEALTH:
		strcpy(tech, "health");
		break;
	case BOTS_SCIENTIST_SPEED:
		strcpy(tech, "speed");
		break;
	case BOTS_SCIENTIST_JUMP:
		strcpy(tech, "jump");
		break;
	case BOTS_SCIENTIST_STRENGTH:
		strcpy(tech, "strength");
		break;
	case BOTS_SCIENTIST_STEALTH:
		strcpy(tech, "stealth");
		break;
		
	// oops - not a valid choice
	default:
		Com_Printf("%i is not a valid choice\n", ((menucommon_s*)ptr)->id);
		break;
	}

	if (tech[0] != '\0')
		trap_Cmd_ExecuteText( EXEC_APPEND, va("UI_to_server_genresearch %s\n", tech));
}

/*
=================
BOTS_ScientistGenResearchMenu_Init
=================
*/
void BOTS_ScientistGenResearchMenu_Init() 
{
	int y;
	char				info[MAX_INFO_STRING];
	uiClientState_t		cs;

	int	weapon_damage		= 0;
	int weapon_firerate		= 0;
	int	weapon_reducedammo	= 0;
	int advanced_armor		= 0;
	int genetic_health		= 0;
	int genetic_speed		= 0;
	int genetic_jump		= 0;
	int genetic_strength	= 0;
	int genetic_stealth		= 0;

	// get the config string and the data it holds
	trap_GetClientState( &cs );
	trap_GetConfigString( CS_BOTS_MENU + cs.clientNum, info, MAX_INFO_STRING );

	weapon_damage		= atoi(Info_ValueForKey( info, "wd"));
	weapon_firerate		= atoi(Info_ValueForKey( info, "wf"));
	weapon_reducedammo	= atoi(Info_ValueForKey( info, "wa"));
	advanced_armor		= atoi(Info_ValueForKey( info, "aa"));
	genetic_health		= atoi(Info_ValueForKey( info, "gh"));
	genetic_speed		= atoi(Info_ValueForKey( info, "gp"));
	genetic_jump		= atoi(Info_ValueForKey( info, "gj"));
	genetic_strength	= atoi(Info_ValueForKey( info, "gs"));
	genetic_stealth		= atoi(Info_ValueForKey( info, "gi"));

	memset( &s_scientistGenResearchMenu, 0 ,sizeof(scientistGenResearchMenu_t) );
	s_scientistGenResearchMenu.menu.wrapAround = qtrue;
	s_scientistGenResearchMenu.menu.fullscreen = qfalse;

	y = 96;
	s_scientistGenResearchMenu.title.generic.type	= MTYPE_PTEXT;
	s_scientistGenResearchMenu.title.generic.flags	= QMF_CENTER_JUSTIFY;
	s_scientistGenResearchMenu.title.generic.x		= 320;
	s_scientistGenResearchMenu.title.generic.y		= y;
	s_scientistGenResearchMenu.title.string			= "SCIENTIST GENERAL RESEARCH MENU";
	s_scientistGenResearchMenu.title.color			= color_bots_menu;
	s_scientistGenResearchMenu.title.style			= UI_CENTER|UI_SMALLFONT;

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.weapondamage.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.weapondamage.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.weapondamage.generic.x			= 320;
	s_scientistGenResearchMenu.weapondamage.generic.y			= y;
	s_scientistGenResearchMenu.weapondamage.generic.id			= BOTS_SCIENTIST_WEAPONDAMAGE;
	s_scientistGenResearchMenu.weapondamage.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.weapondamage.string				= "WEAPON DAMAGE";
	s_scientistGenResearchMenu.weapondamage.color				= color_bots_menu;
	s_scientistGenResearchMenu.weapondamage.style				= UI_CENTER|UI_SMALLFONT;

	if (weapon_damage == 2) {
		s_scientistGenResearchMenu.weapondamage.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.weaponfirerate.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.weaponfirerate.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.weaponfirerate.generic.x			= 320;
	s_scientistGenResearchMenu.weaponfirerate.generic.y			= y;
	s_scientistGenResearchMenu.weaponfirerate.generic.id		= BOTS_SCIENTIST_WEAPONFIRERATE;
	s_scientistGenResearchMenu.weaponfirerate.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.weaponfirerate.string			= "WEAPON FIRE RATE";
	s_scientistGenResearchMenu.weaponfirerate.color				= color_bots_menu;
	s_scientistGenResearchMenu.weaponfirerate.style				= UI_CENTER|UI_SMALLFONT;

	if (weapon_firerate == 2) {
		s_scientistGenResearchMenu.weaponfirerate.generic.flags |= QMF_GRAYED;
	}

		y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.reducedammo.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.reducedammo.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.reducedammo.generic.x		= 320;
	s_scientistGenResearchMenu.reducedammo.generic.y		= y;
	s_scientistGenResearchMenu.reducedammo.generic.id		= BOTS_SCIENTIST_REDUCEDAMMO;
	s_scientistGenResearchMenu.reducedammo.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.reducedammo.string			= "REDUCED AMMO CONSUMPTION";
	s_scientistGenResearchMenu.reducedammo.color			= color_bots_menu;
	s_scientistGenResearchMenu.reducedammo.style			= UI_CENTER|UI_SMALLFONT;

//	if (weapon_reducedammo == 2) {
		s_scientistGenResearchMenu.reducedammo.generic.flags |= QMF_GRAYED;
//	}

	y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.advancedarmor.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.advancedarmor.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.advancedarmor.generic.x			= 320;
	s_scientistGenResearchMenu.advancedarmor.generic.y			= y;
	s_scientistGenResearchMenu.advancedarmor.generic.id			= BOTS_SCIENTIST_ADVANCEDARMOR;
	s_scientistGenResearchMenu.advancedarmor.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.advancedarmor.string				= "ADVANCED ARMOR";
	s_scientistGenResearchMenu.advancedarmor.color				= color_bots_menu;
	s_scientistGenResearchMenu.advancedarmor.style				= UI_CENTER|UI_SMALLFONT;

	if (advanced_armor == 2) {
		s_scientistGenResearchMenu.advancedarmor.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.health.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.health.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.health.generic.x			= 320;
	s_scientistGenResearchMenu.health.generic.y			= y;
	s_scientistGenResearchMenu.health.generic.id		= BOTS_SCIENTIST_HEALTH;
	s_scientistGenResearchMenu.health.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.health.string			= "GENETIC ENHANCEMENT (HEALTH)";
	s_scientistGenResearchMenu.health.color				= color_bots_menu;
	s_scientistGenResearchMenu.health.style				= UI_CENTER|UI_SMALLFONT;

	if (genetic_health == 2) {
		s_scientistGenResearchMenu.health.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.speed.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.speed.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.speed.generic.x			= 320;
	s_scientistGenResearchMenu.speed.generic.y			= y;
	s_scientistGenResearchMenu.speed.generic.id			= BOTS_SCIENTIST_SPEED;
	s_scientistGenResearchMenu.speed.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.speed.string				= "GENETIC ENHANCEMENT (SPEED)";
	s_scientistGenResearchMenu.speed.color				= color_bots_menu;
	s_scientistGenResearchMenu.speed.style				= UI_CENTER|UI_SMALLFONT;

	if (genetic_speed == 2) {
		s_scientistGenResearchMenu.speed.generic.flags |= QMF_GRAYED;
	}

		y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.jump.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.jump.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.jump.generic.x			= 320;
	s_scientistGenResearchMenu.jump.generic.y			= y;
	s_scientistGenResearchMenu.jump.generic.id			= BOTS_SCIENTIST_JUMP;
	s_scientistGenResearchMenu.jump.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.jump.string				= "GENETIC ENHANCEMENT (JUMP)";
	s_scientistGenResearchMenu.jump.color				= color_bots_menu;
	s_scientistGenResearchMenu.jump.style				= UI_CENTER|UI_SMALLFONT;

	if (genetic_jump == 2) {
		s_scientistGenResearchMenu.jump.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.strength.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.strength.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.strength.generic.x			= 320;
	s_scientistGenResearchMenu.strength.generic.y			= y;
	s_scientistGenResearchMenu.strength.generic.id			= BOTS_SCIENTIST_STRENGTH;
	s_scientistGenResearchMenu.strength.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.strength.string				= "GENETIC ENHANCEMENT (STRENGTH)";
	s_scientistGenResearchMenu.strength.color				= color_bots_menu;
	s_scientistGenResearchMenu.strength.style				= UI_CENTER|UI_SMALLFONT;

	if (genetic_strength == 2) {
		s_scientistGenResearchMenu.strength.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.stealth.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.stealth.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.stealth.generic.x		= 320;
	s_scientistGenResearchMenu.stealth.generic.y		= y;
	s_scientistGenResearchMenu.stealth.generic.id		= BOTS_SCIENTIST_STEALTH;
	s_scientistGenResearchMenu.stealth.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.stealth.string			= "STEALTH";
	s_scientistGenResearchMenu.stealth.color			= color_bots_menu;
	s_scientistGenResearchMenu.stealth.style			= UI_CENTER|UI_SMALLFONT;

//	if (genetic_stealth == 2) {
		s_scientistGenResearchMenu.stealth.generic.flags |= QMF_GRAYED;
//	}

	
	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_scientistGenResearchMenu.cancel.generic.type		= MTYPE_PTEXT;
	s_scientistGenResearchMenu.cancel.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistGenResearchMenu.cancel.generic.x			= 320;
	s_scientistGenResearchMenu.cancel.generic.y			= y;
	s_scientistGenResearchMenu.cancel.generic.id		= BOTS_CANCEL;
	s_scientistGenResearchMenu.cancel.generic.callback	= BOTS_ScientistGenResearchMenu_Event; 
	s_scientistGenResearchMenu.cancel.string			= "CANCEL";
	s_scientistGenResearchMenu.cancel.color				= color_bots_menu;
	s_scientistGenResearchMenu.cancel.style				= UI_CENTER|UI_SMALLFONT;

	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.title );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.weapondamage );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.weaponfirerate );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.reducedammo );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.advancedarmor );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.health );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.speed );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.jump );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.strength );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.stealth );
	Menu_AddItem( &s_scientistGenResearchMenu.menu, &s_scientistGenResearchMenu.cancel );
}

void BOTS_ScientistGenResearchMenu_f()
{
	// force as top level menu
	uis.menusp = 0;  

	// set menu cursor to a nice location
	uis.cursorx = 319;
	uis.cursory = 80;

	// setup the menu structure
	BOTS_ScientistGenResearchMenu_Init();

	// show the menus
	UI_PushMenu( &s_scientistGenResearchMenu.menu );
}
